﻿using ArtMath.Attribute;
using ArtMath.Component.CoordinateSystem;
using ArtMath.Component.Polygon;
using ArtMath.Core.Data;
using ArtMath.Resource;
using System;

namespace ArtMath.Component.Point
{
    /// <summary>
    /// 多边形重心（适用于极坐标系）
    /// </summary>
    [Serializable]
    public class PBaryCenter : BaryCenterBase
    {
        PointD rt;

        public PBaryCenter(SketchPad pad, string name, PolygonBase pol, bool addToList = true) : base(pad, name, pol, addToList)
        {
            CoordinateDisplayer = new PropertyDisplayer(this, Resources.Translate("Coordinate"), "({0}, {1})", "ρ", "θ");
        }

        [MultilingualCategory("Parameter")]
        public double ρ
        {
            get { return rt.X; }
        }
        [MultilingualCategory("Parameter")]
        public double θ
        {
            get { return rt.Y; }
        }
        public override void ForceMove(PointD location, bool raiseComponentChangedEvent = true)
        {
            base.ForceMove(location, raiseComponentChangedEvent);
            PolarCoordinate pc = Pad.Coordinate as PolarCoordinate;
            if (pc != null)
            {
                rt = pc.PxytoRT(Pxy);
            }
        }
    }
}
